package fy.uap.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.LogFactory;

import com.seeyon.ctp.util.UUIDLong;

import fy.config.FyConfig;
import fy.uap.bean.InvalidProviderBean;
import fy.uap.bean.InvalidProviderFormBean;
import fy.uap.bean.RangeBean;
import fy.util.DBUtil;
import fy.util.MyUtil;


public class InvalidProviderFormDao {
	private static org.apache.commons.logging.Log log = LogFactory
			.getLog(InvalidProviderFormDao.class);

	private InvalidProviderFormBean invaliProviderFormBean;

	// private final static String findFy_supplier_vendor =
	// "select pk_vendor from fy_supplier_vendor where cvencode = ?";

	private final static String insertLog = "insert into fy_supplier_vendor_history(pk_venhis, pk_vendor, pk_corp, pk_invclass, changetype, changememo, changevouch, changecode, changer, ts, changedate, creater) select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? from dual where exists( select * from fy_supplier_vendor_invclass where pk_vendor=? and trim(pk_corp)=? and pk_invclass=? and (cvendorclass='1' or cvendorclass='2') and (dr='0' or dr is null) )";

	private final static String uapUserID = "0001AA10000000009KX7";

	private Map<String, InvalidProviderBean> invalidProviderMap = new Hashtable<String, InvalidProviderBean>();

	private List<RangeBean> successRangeList;

	private static final String ERPUADATE = "update apps.FYG_PO_UAP_VENDORS@"
			+ FyConfig.getERP_DB_CONFIG().getDblink()
			+ " av set (av.vendors_name, av.flag,av.zt,av.disable_date) = (select v.cvenname cvenname,      decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),   -1,   'N',   decode(vi.cvendorclass, '3', 'N', 'Y')) flag   ,decode(sign(to_date(vi.denddate, 'YYYY-MM-DD') - sysdate),-1,'停用',   decode(vi.cvendorclass,          '1',          '合格',          '2',          '潜在',          '3',          '黑名单',          vi.cvendorclass)) zt,      to_date(vi.denddate, 'YYYY-MM-DD') disable_date from fy_supplier_vendor_invclass vi left join fy_supplier_vendor v on vi.pk_vendor = v.pk_vendor left join bd_corp c on vi.pk_corp = c.pk_corp left join fy_supplier_invclass i on vi.pk_invclass =       i.pk_invclass          where v.cvencode = ? and (vi.dr is null or vi.dr = 0) and av.vendors_num =v.cvencode and av.syb=c.unitname and av.uaplb = i.cinvclasscode )  where av.vendors_num =  ?";

	private List<RangeBean> failPRangeList;
	private List<RangeBean> failQRangeList;

	private long pChangeTrace;
	private long qChangeTrace;

	private List<RangeBean> rangeList;

	private boolean writeToErpSuccess = false;

	public boolean isWriteToErpSuccess() {
		return writeToErpSuccess;
	}

	public List<RangeBean> getFailPRangeList() {
		return failPRangeList;
	}

	public List<RangeBean> getFailQRangeList() {
		return failQRangeList;
	}

	public void setInvaliProviderFormBean(
			InvalidProviderFormBean invaliProviderFormBean) {
		this.invaliProviderFormBean = invaliProviderFormBean;
	}

	public boolean save() {
		boolean success = false;
		Connection conn = null;
		PreparedStatement pst = null;
		PreparedStatement pst1 = null;
		ResultSet rs = null;
		try {
			conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
			pChangeTrace = UUIDLong.longUUID();
			qChangeTrace = UUIDLong.longUUID();

			// select pk_vendor from fy_supplier_vendor where cvencode = ?
			StringBuilder sb = new StringBuilder();
			sb.append("select pk_vendor, cvencode from fy_supplier_vendor where (dr='0' or dr is null) and (denddate is null or to_date(denddate,'yyyy-mm-dd') > to_date( to_char(sysdate, 'yyyy-mm-dd'), 'yyyy-mm-dd' )) and ( ");

			for (int i = 0, size = invaliProviderFormBean
					.getInvalidProviderList().size(); i < size; i++) {
				if (i != 0) {
					sb.append(" or ");
				}

				sb.append("cvencode =? ");
				InvalidProviderBean invaliProvider = invaliProviderFormBean
						.getInvalidProviderList().get(i);
				invalidProviderMap.put(invaliProvider.getProviderCode(),
						invaliProvider);
			}
			sb.append(")");
			pst = conn.prepareStatement(sb.toString());

			for (int i = 0, size = invaliProviderFormBean
					.getInvalidProviderList().size(); i < size; i++) {

				String code = invaliProviderFormBean.getInvalidProviderList()
						.get(i).getProviderCode();

				pst.setString(i + 1, code);
			}

			rs = pst.executeQuery();

			while (rs.next()) {
				String pk_vendor = rs.getString(1);
				String code = rs.getString(2);
				invalidProviderMap.get(code).setPk_vendor(pk_vendor);
			}

			DBUtil.close(rs, pst);

			conn.setAutoCommit(false);

			pst1 = conn.prepareStatement(insertLog);
			// "insert into fy_supplier_vendor_history
			// (pk_venhis, pk_vendor, pk_corp, pk_invclass,
			// changetype, changememo, changevouch, changecode,
			// changer, ts) select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
			// from dual where exists( select * from fy_supplier_vendor_invclass
			// where pk_vendor=? and trim(pk_corp)=? and pk_invclass=? and
			// cvendorclass=? )";

			if ("1".equals(invaliProviderFormBean.getOpinion())) {
				// 停用
				pst = conn
						.prepareStatement("update fy_supplier_vendor_invclass set denddate=?, changeTrace=? where pk_vendor=? and trim(pk_corp)=? and pk_invclass=? and (dr='0' or dr is null) ");
				if (invaliProviderFormBean.getCompanyList() != null) {
					for (int o = 0, cSize = invaliProviderFormBean
							.getCompanyList().size(); o < cSize; o++) {
						String company = invaliProviderFormBean
								.getCompanyList().get(o);
						for (int i = 0, size = invaliProviderFormBean
								.getInvalidProviderList().size(); i < size; i++) {
							InvalidProviderBean invaliProvider = invaliProviderFormBean
									.getInvalidProviderList().get(i);
							if (invaliProviderFormBean.getpTypeList() != null) {
								// 潜在
								for (int m = 0, tSize = invaliProviderFormBean
										.getpTypeList().size(); m < tSize; m++) {
									String pType = invaliProviderFormBean
											.getpTypeList().get(m);
									disableType(pst, pst1, invaliProvider,
											pType, "2", company, pChangeTrace);
								}
							}

							if (invaliProviderFormBean.getqTypeList() != null) {
								// 潜在
								for (int m = 0, tSize = invaliProviderFormBean
										.getqTypeList().size(); m < tSize; m++) {
									String qType = invaliProviderFormBean
											.getqTypeList().get(m);
									disableType(pst, pst1, invaliProvider,
											qType, "1", company, qChangeTrace);
								}
							}
						}
					}
				}

			} else {
				// 黑名单
				pst = conn
						.prepareStatement("update fy_supplier_vendor_invclass set cvendorclass=?, denddate=?, changeTrace=? where pk_vendor=? and trim(pk_corp)=? and ? is null and (dr='0' or dr is null)");
				DBUtil.close(pst1);

				pst1 = conn
						.prepareStatement("insert into fy_supplier_vendor_history(pk_venhis, pk_vendor, pk_corp, pk_invclass, changetype, changememo, changevouch, changecode, changer, ts, changedate, creater) select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? from dual where exists( select * from fy_supplier_vendor_invclass where pk_vendor=? and trim(pk_corp)=? and ? is null and (cvendorclass='1' or cvendorclass='2') and (dr='0' or dr is null) )");

				if (invaliProviderFormBean.getCompanyList() != null) {
					for (int o = 0, cSize = invaliProviderFormBean
							.getCompanyList().size(); o < cSize; o++) {
						String company = invaliProviderFormBean
								.getCompanyList().get(o);
						for (int i = 0, size = invaliProviderFormBean
								.getInvalidProviderList().size(); i < size; i++) {

							InvalidProviderBean invaliProvider = invaliProviderFormBean
									.getInvalidProviderList().get(i);

							writeLog(pst1, invaliProvider, "", "", "黑名单",
									company);

							pst.setString(1, "3");
							pst.setString(2, "");
							pst.setLong(3, pChangeTrace);
							pst.setString(4, invaliProvider.getPk_vendor());
							pst.setString(5, company);

							pst.setString(6, "");
							// pst.setString(7, oldCvendorclass);
							pst.addBatch();

							// if (invaliProviderFormBean.getpTypeList() !=
							// null) {
							// // 潜在
							// for (int m = 0, tSize = invaliProviderFormBean
							// .getpTypeList().size(); m < tSize; m++) {
							//
							// String pType = invaliProviderFormBean
							// .getpTypeList().get(m);
							// writeToblackList(pst, pst1, invaliProvider,
							// pType, "2", company, pChangeTrace);
							// }
							// }
							//
							// if (invaliProviderFormBean.getqTypeList() !=
							// null) {
							// // 合格
							// for (int m = 0, tSize = invaliProviderFormBean
							// .getqTypeList().size(); m < tSize; m++) {
							//
							// String qType = invaliProviderFormBean
							// .getqTypeList().get(m);
							//
							// writeToblackList(pst, pst1, invaliProvider,
							// qType, "1", company, qChangeTrace);
							// }
							// }
						}
					}
				}
			}

			pst1.executeBatch();

			DBUtil.close(pst1);

			pst.executeBatch();

			DBUtil.close(rs, pst);

			if ("1".equals(invaliProviderFormBean.getOpinion())) {
				pst = conn
						.prepareStatement("select i.pk_corp, i.pk_invclass,i.changeTrace, i.pk_vendor from fy_supplier_vendor_invclass i where i.changeTrace=? or i.changeTrace=?");
				pst.setLong(1, qChangeTrace);
				pst.setLong(2, pChangeTrace);
				rs = pst.executeQuery();
				while (rs.next()) {
					if (successRangeList == null) {
						successRangeList = new ArrayList<RangeBean>();
					}
					successRangeList.add(new RangeBean(rs.getString(1), rs
							.getString(2), rs.getLong(3), rs.getString(4)));
				}
			}
			conn.commit();
			success = true;
			sb = null;

			// 查询目标供应商编码对应的供应商信息
			sb = new StringBuilder()
					.append("select i.pk_corp, i.pk_invclass, c.unitname, si.cinvclasscode, v.cvencode, i.cvendorclass, v.cvenname, i.denddate from fy_supplier_vendor_invclass i left join bd_corp c on i.pk_corp = c.pk_corp left join fy_supplier_invclass si on si.pk_invclass = i.pk_invclass left join fy_supplier_vendor v on v.pk_vendor = i.pk_vendor where ");

			boolean first = true;

			if (invaliProviderFormBean.getInvalidProviderList() != null) {
				for (int i = 0, length = invaliProviderFormBean
						.getInvalidProviderList().size(); i < length; i++) {
					if (first) {
						sb.append(" v.cvencode in ( ?  ");
						first = false;
					} else {
						sb.append(" , ? ");
					}
				}
			}

			sb.append(") and (i.dr='0' or i.dr is null) and (i.denddate is null or to_date(i.denddate,'yyyy-mm-dd') > to_date( to_char(sysdate, 'yyyy-mm-dd'), 'yyyy-mm-dd' ))");
			pst = conn.prepareStatement(sb.toString());

			int index = 1;

			if (invaliProviderFormBean.getInvalidProviderList() != null) {
				for (int i = 0, length = invaliProviderFormBean
						.getInvalidProviderList().size(); i < length; i++) {
					pst.setString(index, invaliProviderFormBean
							.getInvalidProviderList().get(i).getProviderCode());
					index++;
				}
			}
			rs = pst.executeQuery();
			while (rs.next()) {
				// select i.pk_corp, i.pk_invclass, c.unitname,
				// si.cinvclasscode, v.cvencode, i.cvendorclass
				if (rangeList == null) {
					rangeList = new ArrayList<RangeBean>();
				}
				rangeList
						.add(new RangeBean(rs.getString(1), rs.getString(2), rs
								.getString(3), rs.getString(5),
								rs.getString(4), rs.getString(6), rs
										.getString(7), rs.getString(8)));
			}

			try {
				// ERP更新
				pst = conn.prepareStatement(ERPUADATE);
				for (int i = 0, size = invaliProviderFormBean
						.getInvalidProviderList().size(); i < size; i++) {
					pst.setString(1, invaliProviderFormBean
							.getInvalidProviderList().get(i).getProviderCode());
					pst.setString(2, invaliProviderFormBean
							.getInvalidProviderList().get(i).getProviderCode());
					pst.addBatch();
				}
				pst.executeBatch();

				conn.commit();
				writeToErpSuccess = true;
			} catch (Exception e) {
				DBUtil.rollback(conn);
				e.printStackTrace();
				log.error(
						"《供应商导出》写入ERP数据库异常,单据编号： "
								+ invaliProviderFormBean.getNumber(), e);
				writeToErpSuccess = false;
			}

		} catch (Exception e) {
			success = false;
			DBUtil.rollback(conn);
			e.printStackTrace();
			log.error("供应商导出审批数据导入UPA异常", e);
		} finally {
			DBUtil.setAutoCommit(conn, true);
			DBUtil.close(pst1);
			DBUtil.close(rs, pst, conn);
		}
		if ("1".equals(invaliProviderFormBean.getOpinion())) {
			setFailRangeList();
		}

		return success;
	}

	private void setFailRangeList() {
		List<String> companyList = invaliProviderFormBean.getCompanyList();
		int companySize = companyList == null ? 0 : companyList.size();
		int invalidProviderSize = invaliProviderFormBean
				.getInvalidProviderList().size();
		int pListSize = invaliProviderFormBean.getpTypeList() == null ? 0
				: invaliProviderFormBean.getpTypeList().size();
		int qListSize = invaliProviderFormBean.getqTypeList() == null ? 0
				: invaliProviderFormBean.getqTypeList().size();
		if (successRangeList == null
				|| successRangeList.size() < (companySize * invalidProviderSize
						* pListSize + companySize * invalidProviderSize
						* qListSize)) {
			boolean fail = true;
			for (int a = 0; a < invalidProviderSize; a++) {
				String pk_vendor = invaliProviderFormBean
						.getInvalidProviderList().get(a).getPk_vendor();
				for (int o = 0; o < companySize; o++) {
					String company = invaliProviderFormBean.getCompanyList()
							.get(o);

					// 潜在
					for (int m = 0; m < pListSize; m++) {
						String pType = invaliProviderFormBean.getpTypeList()
								.get(m);
						RangeBean bean = null;
						for (int i = 0, size = successRangeList == null ? 0
								: successRangeList.size(); i < size; i++) {
							bean = successRangeList.get(i);
							if (bean.getChangeTrace() == pChangeTrace) {
								if (bean.getPk_corp().equals(company)
										&& bean.getPk_invclass().equals(pType)
										&& pk_vendor
												.equals(bean.getPk_vendor())) {
									fail = false;
									break;
								}
							}
							bean = null;
						}
						if (fail) {
							if (failPRangeList == null) {
								failPRangeList = new ArrayList<RangeBean>();
							}
							bean = new RangeBean(company, pType, 0,
									invaliProviderFormBean
											.getInvalidProviderList().get(a)
											.getProviderCode());
							failPRangeList.add(bean);
						}
						fail = true;
						bean = null;
					}
					// 合格
					for (int m = 0; m < qListSize; m++) {
						String qType = invaliProviderFormBean.getqTypeList()
								.get(m);
						RangeBean bean = null;
						for (int i = 0, size = successRangeList == null ? 0
								: successRangeList.size(); i < size; i++) {
							bean = successRangeList.get(i);
							if (bean.getChangeTrace() == qChangeTrace) {

								if (bean.getPk_corp().equals(company)
										&& bean.getPk_invclass().equals(qType)
										&& pk_vendor
												.equals(bean.getPk_vendor())) {
									fail = false;
									break;
								}
							}
							bean = null;
						}
						if (fail) {
							if (failQRangeList == null) {
								failQRangeList = new ArrayList<RangeBean>();
							}
							bean = new RangeBean(company, qType, 0,
									invaliProviderFormBean
											.getInvalidProviderList().get(a)
											.getProviderCode());
							failQRangeList.add(bean);
							bean = null;
						}
						fail = true;
					}

				}
			}
		}

	}

	/**
	 * 停用表单
	 * 
	 * @param pst
	 * @param pst1
	 * @param invaliProvider
	 * @param type
	 * @param oldCvendorclass
	 * @throws SQLException
	 */
	private void disableType(PreparedStatement pst, PreparedStatement pst1,
			InvalidProviderBean invaliProvider, String type,
			String oldCvendorclass, String company, long changeTrace)
			throws SQLException {
		if (type != null && !"".equals(type)) {

			writeLog(pst1, invaliProvider, type, oldCvendorclass, "停用", company);
			// update fy_supplier_vendor_invclass set denddate=?
			// where pk_vendor=? and trim(pk_corp)=? and pk_invclass=?
			// and cvendorclass=? and (dr='0' or dr is null)
			pst.setString(1, invaliProvider.getInvalidDate());
			pst.setLong(2, changeTrace);
			pst.setString(3, invaliProvider.getPk_vendor());
			pst.setString(4, company);

			pst.setString(5, type);
			// pst.setString(6, oldCvendorclass);
			// pst.setString(6, MyUtil.getTodayDateStr());
			pst.addBatch();
		}
	}

	/**
	 * 加入黑名单
	 * 
	 * @param pst
	 * @param pst1
	 * @param invaliProvider
	 * @param type
	 * @param oldCvendorclass
	 * @throws SQLException
	 */
	// private void writeToblackList(PreparedStatement pst,
	// PreparedStatement pst1, InvalidProviderBean invaliProvider,
	// String type, String oldCvendorclass, String company,
	// long changeTrace) throws SQLException {
	// if (type != null && !"".equals(type)) {
	//
	// writeLog(pst1, invaliProvider, type, oldCvendorclass, "黑名单",
	// company);
	//
	// pst.setString(1, "3");
	// pst.setString(2, "");
	// pst.setLong(3, changeTrace);
	// pst.setString(4, invaliProvider.getPk_vendor());
	// pst.setString(5, company);
	//
	// pst.setString(6, type);
	// // pst.setString(7, oldCvendorclass);
	// pst.addBatch();
	// }
	// }

	/**
	 * 写日志
	 * 
	 * @param pst1
	 * @param invaliProvider
	 * @param type
	 * @param oldCvendorclass
	 * @param operate
	 * @throws SQLException
	 */
	private void writeLog(PreparedStatement pst1,
			InvalidProviderBean invaliProvider, String type,
			String oldCvendorclass, String operate, String company)
			throws SQLException {
		// "insert into fy_supplier_vendor_history
		// (pk_venhis, pk_vendor, pk_corp, pk_invclass,
		// changetype, changememo, changevouch, changecode,
		// changer, ts) select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
		// from dual where exists( select * from fy_supplier_vendor_invclass
		// where pk_vendor=? and trim(pk_corp)=? and pk_invclass=? and
		// cvendorclass=? )";l;

		pst1.setString(1,
				String.valueOf(UUIDLong.longUUID()));
		pst1.setString(2, invaliProvider.getPk_vendor());
		pst1.setString(3, company);
		pst1.setString(4, type);
		pst1.setString(5, operate);
		pst1.setString(6, this.invaliProviderFormBean.getReason());
		pst1.setString(7, "OA供应商导出批准表");
		pst1.setString(8, this.invaliProviderFormBean.getNumber());
		pst1.setString(9, uapUserID);
		pst1.setString(10, MyUtil.getNowStr());
		pst1.setString(11, MyUtil.getTodayDateStr());
		pst1.setString(12, invaliProviderFormBean.getMemberCode());
		pst1.setString(13, invaliProvider.getPk_vendor());
		pst1.setString(14, company);
		pst1.setString(15, type);

		pst1.addBatch();
	}

	// /**
	// * 写入到ERP数据库
	// */
	// private void writeToErp() {
	//
	// Connection conn = null;
	// PreparedStatement pst = null;
	// try {
	//
	// // FileOutputStream fos = new FileOutputStream("E:/1111");
	// // fos.write(providerImportFormBean.printFields().getBytes());
	// // fos.flush();
	// // fos.close();
	//
	// conn = DBUtil.connect(ERP_OAConstant.ERPDriverClassName,
	// ERP_OAConstant.ERPURL, ERP_OAConstant.ERPUserName,
	// ERP_OAConstant.ERPPassword);
	//
	// conn.setAutoCommit(false);
	//
	// pst = conn
	// .prepareStatement("delete from apps.FYG_PO_UAP_VENDORS v where v.vendors_num = ?  and v.ZT<>'客户' ");
	// // update apps.FYG_PO_UAP_VENDORS set ZT=? where VENDORS_NUM=?
	// // and
	// // SY=? and UAPLB=?
	//
	// if (invaliProviderFormBean.getInvalidProviderList() != null) {
	// for (int i = 0, length = invaliProviderFormBean
	// .getInvalidProviderList().size(); i < length; i++) {
	// pst.setString(1, invaliProviderFormBean
	// .getInvalidProviderList().get(i).getProviderCode());
	// pst.addBatch();
	// }
	// }
	//
	// // pst.setString(1,
	// // mergerProviderFormBean.getNewProviderCode());
	//
	// pst.executeBatch();
	// DBUtil.close(pst);
	// // insert into fy_supplier_vendor_invclass (pk_veninv, pk_corp,
	// // pk_invclass, cvendorclass, ts, pk_vendor, dvendevdate,
	// // changeTrace, creater) select ?, ?, ?, ?, ?, ?, ?, ?, ? from
	// // dual
	// // where not exists ( select * from fy_supplier_vendor_invclass
	// // where pk_corp=? and pk_invclass=? and pk_vendor=? and (dr='0'
	// // or
	// // dr is null) and ( cvendorclass = '3' or cvendorclass = '0'))
	//
	// if (rangeList != null) {
	//
	// pst = conn
	// .prepareStatement("insert into apps.FYG_PO_UAP_VENDORS (VENDORS_NUM, VENDORS_NAME, SYB, UAPLB, ZT,disable_date, flag ) values(  ?, ?, ?, ?, ?, to_date(?,'YYYY-MM-DD'), ? ) ");
	// // insert into apps.FYG_PO_UAP_VENDORS (VENDORS_NUM 供应商编号,
	// // VENDORS_NAME 供应商名称, SYB 事业部, UAPLB UAP类别, ZT 状态) select ?, ?,
	// // ?,
	// // ?, ?, ?, ?, ?, ? from dual where not exists ( select * from
	// // apps.FYG_PO_UAP_VENDORS f where f.VENDORS_NUM=? and f.SY=?
	// // and
	// // f.UAPLB=?)");
	// RangeBean range = null;
	// for (int i = 0, size = rangeList.size(); i < size; i++) {
	// range = rangeList.get(i);
	//
	// pst.setString(1, range.getProviderCode());
	// pst.setString(2, range.getProviderName());
	// pst.setString(3, range.getCorpName());
	// pst.setString(4, range.getInvclassCode());
	// pst.setString(
	// 5,
	// "2".equals(range.getCvendorclass()) ? "潜在"
	// : "1".equals(range.getCvendorclass()) ? "合格"
	// : ("3".equals(range
	// .getCvendorclass()) ? "黑名单"
	// : range.getCvendorclass()));
	// pst.setString(6, range.getDenddate());
	// pst.setString(7, "3".equals(range.getCvendorclass()) ? "N"
	// : "Y");
	// // pst.setString(6, range.getProviderCode());
	// // pst.setString(7, range.getCorpName());
	// // pst.setString(8, range.getInvclassCode());
	// pst.addBatch();
	// range = null;
	// }
	// pst.executeBatch();
	// } else {
	// log.warn("《供应商导出》写入ERP数据库为空,单据编号： "
	// + invaliProviderFormBean.getNumber());
	//
	// }
	// conn.commit();
	//
	// writeToErpSuccess = true;
	//
	// } catch (Exception e) {
	// DBUtil.rollback(conn);
	// DBUtil.setAutoCommit(conn, true);
	// e.printStackTrace();
	// log.error(
	// "《供应商导出》写入ERP数据库异常,单据编号： "
	// + invaliProviderFormBean.getNumber(), e);
	// writeToErpSuccess = false;
	// } finally {
	// DBUtil.setAutoCommit(conn, true);
	// DBUtil.close(pst, conn);
	// }
	//
	// }

	// public static void main(String[] args) {
	// StringBuilder sb = new StringBuilder()
	// .append("select i.pk_corp, i.pk_invclass, c.unitname, si.cinvclasscode, v.cvencode, i.cvendorclass, v.cvenname, i.denddate from fy_supplier_vendor_invclass i left join bd_corp c on i.pk_corp = c.pk_corp left join fy_supplier_invclass si on si.pk_invclass = i.pk_invclass left join fy_supplier_vendor v on v.pk_vendor = i.pk_vendor where ");
	//
	// boolean first = true;
	//
	// List<String> failPRangeList = new ArrayList<String>();
	// failPRangeList.add("1111");
	// failPRangeList.add("1112");
	// failPRangeList.add("1113");
	// failPRangeList.add("1114");
	// failPRangeList.add("1115");
	// failPRangeList.add("1116");
	//
	// List<String> failQRangeList = new ArrayList<String>();
	//
	// failQRangeList.add("2111");
	// failQRangeList.add("2112");
	// failQRangeList.add("2113");
	// failQRangeList.add("2114");
	// failQRangeList.add("2115");
	// failQRangeList.add("2116");
	//
	// if (failPRangeList != null) {
	// for (int i = 0, length = failPRangeList.size(); i < length; i++) {
	// if (first) {
	// sb.append(" v.cvencode in ( ?  ");
	// first = false;
	// } else {
	// sb.append(" , ? ");
	// }
	// }
	// }
	//
	// if (failQRangeList != null) {
	// for (int i = 0, length = failQRangeList.size(); i < length; i++) {
	// if (first) {
	// sb.append(" v.cvencode in ( ?  ");
	// first = false;
	// } else {
	// sb.append(" , ? ");
	// }
	// }
	// }
	//
	// sb.append(") and (i.dr='0' or i.dr is null) and (i.denddate is null or to_date(i.denddate,'yyyy-mm-dd') > to_date( to_char(sysdate, 'yyyy-mm-dd'), 'yyyy-mm-dd' ))");
	//
	// System.out.println(sb);
	//
	// }
}
